package cn.sofwin.day0328;

public class Test02 {
    static int distence = 0;
    private static void Run(){
        while(distence < 1000){
            String name = Thread.currentThread().getName();
            synchronized (Test02.class){
                if (distence < 1000) {
                    System.out.println(name + "号选手拿到了接力棒！起点：" + distence);
                    for (int i = 10; i <= 100; i += 10) {
                        System.out.println(name + "号选手跑了" + i + "米！");
                        try {
                            Thread.sleep(10);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
            distence += 100;
        }
    }
    static class Athlete implements Runnable{
        @Override
        public void run() {
            Run();
        }
    }
    public static void main(String[] args) {
        Athlete athlete = new Athlete();
        Thread Ath1 = new Thread(athlete, "1");
        Thread Ath2 = new Thread(athlete, "2");
        Thread Ath3 = new Thread(athlete, "3");
        Thread Ath4 = new Thread(athlete, "4");

        Ath1.start();
        Ath2.start();
        Ath3.start();
        Ath4.start();
    }
}
